<?php
    include('incs/database.inc.php');
	include('incs/config.inc.php');
	include('incs/function.inc.php');
	db_open();

    $bulan = $_GET["bulan"];
    $tahun = $_GET["tahun"];

	$query_cek = "SELECT *
				FROM `view_l02` WHERE `bulan`=$bulan AND `tahun`=$tahun";
	$hasil_cek = db_query($query_cek);
    $jml_cek = db_num_rows($hasil_cek);
	if($jml_cek==0){
		$query_satpas = "SELECT * FROM `SATPAS`";
	    $hasil_satpas = db_query($query_satpas);
        while($satpas_data = db_fetch_array($hasil_satpas)){
		    $query_insert = "INSERT INTO `l02` (`ID_SATPAS`,`TAHUN`,`BULAN`) VALUES ($satpas_data[ID],$tahun,$bulan)";
            db_query($query_insert);
        }
    }

    $query_b = "SELECT `DESKRIPSI` FROM `bulan` WHERE `ID`=$bulan LIMIT 1";
	$hasil_b = db_query($query_b);
	$bulannya = db_fetch_array($hasil_b);

    $query_s = "SELECT *
				FROM `view_l02` WHERE `bulan`=$bulan AND `tahun`=$tahun";
	$hasil = db_query($query_s);
    $jumlah = db_num_rows($hasil);
    while($tampil_data = db_fetch_array($hasil)){
		$arrdata[] = $tampil_data;
	}
?>
<html>
<head>
    <script type="text/javascript" src="images/jquery.js"></script>
    <script type="text/javascript" src="images/cufon-yui.js"></script>
    <script type="text/javascript" src="images/Gotham_Book_400_font.js"></script>
    <script type="text/javascript">
        Cufon.replace('.gotham, #content');
    </script>
    <link rel="stylesheet" type="text/css" href="images/sim.css" />
    <title>Sistem Informasi SIM - POLDA RIAU</title>
</head>
<body>
<div style="margin: 0">
       <div id="content">
            <span><?php echo $bulannya['DESKRIPSI']." ".$tahun;?></span>
            <div class="switch"><img src="images/headersim.png" /></div>
       </div>
       <br class="clear" />
       <form method="post" action="./simpan_data_2.php">
            <table class="table-common" align="left" cellpadding="5" cellspacing="0">
                  <tr align="center">
                      <th width="30" height="43" rowspan="3">NO.</th>
                      <th width="200" rowspan="3" rowspan="3">POLDA / SATPAS</th>
                      <th width="320" colspan="16">GOLONGAN SIM</th>
                      <th width="40" colspan="3">JUMLAH</th>
                  </tr>
                  <tr>
                      <th colspan="3">BARU</th>
                      <th colspan="8">PERPANJANGAN</th>
                      <th colspan="5">PENINGKATAN</th>
                      <th rowspan="2">PROD SIM</th>
                      <th rowspan="2">SIM RUSAK</th>
                      <th rowspan="2">BIT SIM</th>
                  </tr>
                  <tr>
                      <th width="40">A</th>
        			  <th width="40">C</th>
        			  <th width="40">D</th>
                      <th width="40">A</th>
                      <th width="40">AU</th>
        			  <th width="40">C</th>
        			  <th width="40">D</th>
        			  <th width="40">BI</th>
                      <th width="40">BIU</th>
                      <th width="40">BII</th>
        			  <th width="40">BIIU</th>
        			  <th width="40">AU</th>
        			  <th width="40">BI</th>
                      <th width="40">BIU</th>
                      <th width="40">BII</th>
        			  <th width="40">BIIU</th>
                  </tr>
                  <?php $seq_number=1;?>
                  <?php foreach($arrdata AS $data) { ?>
                  <?php if($seq_number%2==0):?><tr class="table-common-special">
                  <?php else:?> <tr> <?php endif ?>
                      <td><?php echo $seq_number;?></td>
                      <input name="data[<?php echo $seq_number-1 ?>][id]" type="hidden" value="<?php echo $data['ID_SATPAS'];?>" />
                      <td><?php echo $data['NAMA_SATPAS'];?></td>
                      <td align="center"><input style="font-size:11px;" name="data[<?php echo $seq_number-1 ?>][gba]" id="gba<?=$seq_number-1;?>" type="text" size="4" maxlength="5" onkeyup="if(!isNaN(this.value)){
      					if(this.value&lt;0){
      						alert('Maaf, Nilai Tidak boleh minus....!');
      						this.value = 0;
      					}
          				 }else{
          					alert('Maaf, Kolom Harus Diisi Dengan Angka....!');
          					if(parseFloat(this.value)&gt;0){
          						this.value=parseFloat(this.value);
          					}else{
          						this.value=0;
          					}
          				 }" value="<?php echo $data['GOL_BARU_A'];?>" <?php echo $data['GOL_BARU_A'];?>/>
                       </td>
                       <td align="center"><input style="font-size:11px;" name="data[<?php echo $seq_number-1 ?>][gbc]" id="gbc<?=$seq_number-1;?>" type="text" size="4" maxlength="5" onkeyup="if(!isNaN(this.value)){
      					if(this.value&lt;0){
      						alert('Maaf, Nilai Tidak boleh minus....!');
      						this.value = 0;
      					}
          				 }else{
          					alert('Maaf, Kolom Harus Diisi Dengan Angka....!');
          					if(parseFloat(this.value)&gt;0){
          						this.value=parseFloat(this.value);
          					}else{
          						this.value=0;
          					}
          				 }" value="<?php echo $data['GOL_BARU_C'];?>" <?php echo $data['GOL_BARU_C'];?>/>
                       </td>
                       <td align="center"><input style="font-size:11px;" name="data[<?php echo $seq_number-1 ?>][gbd]" id="gbd<?=$seq_number-1;?>" type="text" size="4" maxlength="5" onkeyup="if(!isNaN(this.value)){
      					if(this.value&lt;0){
      						alert('Maaf, Nilai Tidak boleh minus....!');
      						this.value = 0;
      					}
      				 }else{
      					alert('Maaf, Kolom Harus Diisi Dengan Angka....!');
      					if(parseFloat(this.value)&gt;0){
      						this.value=parseFloat(this.value);
      					}else{
      						this.value=0;
      					}
      				 }" value="<?php echo $data['GOL_BARU_D'];?>" <?php echo $data['GOL_BARU_D'];?>/>
                       </td>


                        <td align="center"><input style="font-size:11px;" name="data[<?php echo $seq_number-1 ?>][gpa]" id="gpa<?=$seq_number-1;?>" type="text" size="4" maxlength="5" onkeyup="if(!isNaN(this.value)){
      					if(this.value&lt;0){
      						alert('Maaf, Nilai Tidak boleh minus....!');
      						this.value = 0;
      					}
          				 }else{
          					alert('Maaf, Kolom Harus Diisi Dengan Angka....!');
          					if(parseFloat(this.value)&gt;0){
          						this.value=parseFloat(this.value);
          					}else{
          						this.value=0;
          					}
          				 }" value="<?php echo $data['GOL_PANJANG_A'];?>" <?php echo $data['GOL_PANJANG_A'];?>/>
                       </td>
                        <td><input style="font-size:11px;" name="data[<?php echo $seq_number-1 ?>][gpau]" id="gpau<?=$seq_number-1;?>" type="text" size="4" maxlength="5" onkeyup="if(!isNaN(this.value)){
      					if(this.value&lt;0){
      						alert('Maaf, Nilai Tidak boleh minus....!');
      						this.value = 0;
      					}
      				 }else{
      					alert('Maaf, Kolom Harus Diisi Dengan Angka....!');
      					if(parseFloat(this.value)&gt;0){
      						this.value=parseFloat(this.value);
      					}else{
      						this.value=0;
      					}
      				 }" value="<?php echo $data['GOL_PANJANG_AU'];?>" <?php echo $data['GOL_PANJANG_AU'];?>/></td>
                       <td align="center"><input style="font-size:11px;" name="data[<?php echo $seq_number-1 ?>][gbc]" id="gbc<?=$seq_number-1;?>" type="text" size="4" maxlength="5" onkeyup="if(!isNaN(this.value)){
      					if(this.value&lt;0){
      						alert('Maaf, Nilai Tidak boleh minus....!');
      						this.value = 0;
      					}
          				 }else{
          					alert('Maaf, Kolom Harus Diisi Dengan Angka....!');
          					if(parseFloat(this.value)&gt;0){
          						this.value=parseFloat(this.value);
          					}else{
          						this.value=0;
          					}
          				 }" value="<?php echo $data['GOL_PANJANG_C'];?>" <?php echo $data['GOL_PANJANG_C'];?>/>
                       </td>
                       <td align="center"><input style="font-size:11px;" name="data[<?php echo $seq_number-1 ?>][gbd]" id="gbd<?=$seq_number-1;?>" type="text" size="4" maxlength="5" onkeyup="if(!isNaN(this.value)){
      					if(this.value&lt;0){
      						alert('Maaf, Nilai Tidak boleh minus....!');
      						this.value = 0;
      					}
      				 }else{
      					alert('Maaf, Kolom Harus Diisi Dengan Angka....!');
      					if(parseFloat(this.value)&gt;0){
      						this.value=parseFloat(this.value);
      					}else{
      						this.value=0;
      					}
      				 }" value="<?php echo $data['GOL_PANJANG_D'];?>" <?php echo $data['GOL_PANJANG_D'];?>/>
                       </td>
                       <td><input style="font-size:11px;" name="data[<?php echo $seq_number-1 ?>][gpbi]" id="gpbi<?=$seq_number-1;?>" type="text" size="4" maxlength="5" onkeyup="if(!isNaN(this.value)){
      					if(this.value&lt;0){
      						alert('Maaf, Nilai Tidak boleh minus....!');
      						this.value = 0;
      					}
      				 }else{
      					alert('Maaf, Kolom Harus Diisi Dengan Angka....!');
      					if(parseFloat(this.value)&gt;0){
      						this.value=parseFloat(this.value);
      					}else{
      						this.value=0;
      					}
      				 }" value="<?php echo $data['GOL_PANJANG_BI'];?>" <?php echo $data['GOL_PANJANG_BI'];?>/></td>
                       <td><input style="font-size:11px;" name="data[<?php echo $seq_number-1 ?>][gpbiu]" id="gpbiu<?=$seq_number-1;?>" type="text" size="4" maxlength="5" onkeyup="if(!isNaN(this.value)){
      					if(this.value&lt;0){
      						alert('Maaf, Nilai Tidak boleh minus....!');
      						this.value = 0;
      					}
      				 }else{
      					alert('Maaf, Kolom Harus Diisi Dengan Angka....!');
      					if(parseFloat(this.value)&gt;0){
      						this.value=parseFloat(this.value);
      					}else{
      						this.value=0;
      					}
      				 }" value="<?php echo $data['GOL_PANJANG_BIU'];?>" <?php echo $data['GOL_PANJANG_BIU'];?>/></td>
                       <td><input style="font-size:11px;" name="data[<?php echo $seq_number-1 ?>][gpbii]" id="gpbii<?=$seq_number-1;?>" type="text" size="4" maxlength="5" onkeyup="if(!isNaN(this.value)){
      					if(this.value&lt;0){
      						alert('Maaf, Nilai Tidak boleh minus....!');
      						this.value = 0;
      					}
      				 }else{
      					alert('Maaf, Kolom Harus Diisi Dengan Angka....!');
      					if(parseFloat(this.value)&gt;0){
      						this.value=parseFloat(this.value);
      					}else{
      						this.value=0;
      					}
      				 }" value="<?php echo $data['GOL_PANJANG_BII'];?>" <?php echo $data['GOL_PANJANG_BII'];?>/></td>
                       <td><input style="font-size:11px;" name="data[<?php echo $seq_number-1 ?>][gpbiiu]" id="gpbiiu<?=$seq_number-1;?>" type="text" size="4" maxlength="5" onkeyup="if(!isNaN(this.value)){
      					if(this.value&lt;0){
      						alert('Maaf, Nilai Tidak boleh minus....!');
      						this.value = 0;
      					}
      				 }else{
      					alert('Maaf, Kolom Harus Diisi Dengan Angka....!');
      					if(parseFloat(this.value)&gt;0){
      						this.value=parseFloat(this.value);
      					}else{
      						this.value=0;
      					}
      				 }" value="<?php echo $data['GOL_PANJANG_BIIU'];?>" <?php echo $data['GOL_PANJANG_BIIU'];?>/></td>

                      <td><input style="font-size:11px;" name="data[<?php echo $seq_number-1 ?>][gtau]" id="gtau<?=$seq_number-1;?>" type="text" size="4" maxlength="5" onkeyup="if(!isNaN(this.value)){
      					if(this.value&lt;0){
      						alert('Maaf, Nilai Tidak boleh minus....!');
      						this.value = 0;
      					}
      				 }else{
      					alert('Maaf, Kolom Harus Diisi Dengan Angka....!');
      					if(parseFloat(this.value)&gt;0){
      						this.value=parseFloat(this.value);
      					}else{
      						this.value=0;
      					}
      				 }" value="<?php echo $data['GOL_TINGKAT_AU'];?>" <?php echo $data['GOL_TINGKAT_AU'];?>/></td>
                       <td><input style="font-size:11px;" name="data[<?php echo $seq_number-1 ?>][gtbi]" id="gtbi<?=$seq_number-1;?>" type="text" size="4" maxlength="5" onkeyup="if(!isNaN(this.value)){
      					if(this.value&lt;0){
      						alert('Maaf, Nilai Tidak boleh minus....!');
      						this.value = 0;
      					}
      				 }else{
      					alert('Maaf, Kolom Harus Diisi Dengan Angka....!');
      					if(parseFloat(this.value)&gt;0){
      						this.value=parseFloat(this.value);
      					}else{
      						this.value=0;
      					}
      				 }" value="<?php echo $data['GOL_TINGKAT_BI'];?>" <?php echo $data['GOL_TINGKAT_BI'];?>/></td>
                       <td><input style="font-size:11px;" name="data[<?php echo $seq_number-1 ?>][gtbiu]" id="gtbiu<?=$seq_number-1;?>" type="text" size="4" maxlength="5" onkeyup="if(!isNaN(this.value)){
      					if(this.value&lt;0){
      						alert('Maaf, Nilai Tidak boleh minus....!');
      						this.value = 0;
      					}
      				 }else{
      					alert('Maaf, Kolom Harus Diisi Dengan Angka....!');
      					if(parseFloat(this.value)&gt;0){
      						this.value=parseFloat(this.value);
      					}else{
      						this.value=0;
      					}
      				 }" value="<?php echo $data['GOL_TINGKAT_BIU'];?>" <?php echo $data['GOL_TINGKAT_BIU'];?>/></td>
                       <td><input style="font-size:11px;" name="data[<?php echo $seq_number-1 ?>][gtbii]" id="gtbii<?=$seq_number-1;?>" type="text" size="4" maxlength="5" onkeyup="if(!isNaN(this.value)){
      					if(this.value&lt;0){
      						alert('Maaf, Nilai Tidak boleh minus....!');
      						this.value = 0;
      					}
      				 }else{
      					alert('Maaf, Kolom Harus Diisi Dengan Angka....!');
      					if(parseFloat(this.value)&gt;0){
      						this.value=parseFloat(this.value);
      					}else{
      						this.value=0;
      					}
      				 }" value="<?php echo $data['GOL_TINGKAT_BII'];?>" <?php echo $data['GOL_TINGKAT_BII'];?>/></td>
                       <td><input style="font-size:11px;" name="data[<?php echo $seq_number-1 ?>][gtbiiu]" id="gtbiiu<?=$seq_number-1;?>" type="text" size="4" maxlength="5" onkeyup="if(!isNaN(this.value)){
      					if(this.value&lt;0){
      						alert('Maaf, Nilai Tidak boleh minus....!');
      						this.value = 0;
      					}
      				 }else{
      					alert('Maaf, Kolom Harus Diisi Dengan Angka....!');
      					if(parseFloat(this.value)&gt;0){
      						this.value=parseFloat(this.value);
      					}else{
      						this.value=0;
      					}
      				 }" value="<?php echo $data['GOL_TINGKAT_BIIU'];?>" <?php echo $data['GOL_TINGKAT_BIIU'];?>/></td>

                      <td><input style="font-size:11px;" name="data[<?php echo $seq_number-1 ?>][jp]" id="jp<?=$seq_number-1;?>" type="text" size="4" maxlength="5" onkeyup="if(!isNaN(this.value)){
      					if(this.value&lt;0){
      						alert('Maaf, Nilai Tidak boleh minus....!');
      						this.value = 0;
      					}
      				 }else{
      					alert('Maaf, Kolom Harus Diisi Dengan Angka....!');
      					if(parseFloat(this.value)&gt;0){
      						this.value=parseFloat(this.value);
      					}else{
      						this.value=0;
      					}
      				 }" value="<?php echo $data['JML_PROD'];?>" <?php echo $data['JML_PROD'];?>/></td>
                       <td><input style="font-size:11px;" name="data[<?php echo $seq_number-1 ?>][jr]" id="jr<?=$seq_number-1;?>" type="text" size="4" maxlength="5" onkeyup="if(!isNaN(this.value)){
      					if(this.value&lt;0){
      						alert('Maaf, Nilai Tidak boleh minus....!');
      						this.value = 0;
      					}
      				 }else{
      					alert('Maaf, Kolom Harus Diisi Dengan Angka....!');
      					if(parseFloat(this.value)&gt;0){
      						this.value=parseFloat(this.value);
      					}else{
      						this.value=0;
      					}
      				 }" value="<?php echo $data['JML_RUSAK'];?>" <?php echo $data['JML_RUSAK'];?>/></td>
                       <td><input style="font-size:11px;" name="data[<?php echo $seq_number-1 ?>][jb]" id="jb<?=$seq_number-1;?>" type="text" size="4" maxlength="5" onkeyup="if(!isNaN(this.value)){
      					if(this.value&lt;0){
      						alert('Maaf, Nilai Tidak boleh minus....!');
      						this.value = 0;
      					}
      				 }else{
      					alert('Maaf, Kolom Harus Diisi Dengan Angka....!');
      					if(parseFloat(this.value)&gt;0){
      						this.value=parseFloat(this.value);
      					}else{
      						this.value=0;
      					}
      				 }" value="<?php echo $data['JML_BIT'];?>" <?php echo $data['JML_BIT'];?>/></td>
                  </tr>
                  <?php $seq_number++;?>
                  <?php } ?>
            </table>
            <br class="clear" />
            <div align="left">
               <input type="hidden" name="bulan" value="<?php echo $bulan?>">
               <input type="hidden" name="tahun" value="<?php echo $tahun?>">
               <input type="hidden" name="jumlah" value="<?php echo $jumlah?>">
               <button class="stdbtn" type="submit" title="Klik untuk menyimpan data" name="Submit" value="Simpan">SIMPAN</button>&nbsp;
               <button class="stdbtn" type="button" title="Klik untuk kembali" onclick="self.location='./index2.php'">KEMBALI</button>
            </div>
       </form>
</div>
</body>
</html>
